//
//  MessageController.m
//  CMJWeibo
//
//  Created by BH on 15/12/4.
//
//

#import "MessageController.h"
#import "CMJCommonGroup.h"
#import "CMJCommonArrowItem.h"
#import "SearchBar.h"
#import "UIView+MJ.h"
#import "CMJCommon.h"
#import "CMJNavgationController.h"
#import "FindPeopleController.h"

@implementation MessageController

-(void)viewDidLoad
{
    [super viewDidLoad];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"发现群" style:UIBarButtonItemStylePlain target:self action:@selector(findGroup)];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"消息" style:UIBarButtonItemStylePlain target:self action:@selector(message)];
    
    [self setupItems];
}

/** 发现群 */
-(void)findGroup
{}

/** 消息 */
-(void)message
{}

/** cell组 */
-(void)setupItems
{
    CMJCommonGroup *group = [self addGroup];
    
    CMJCommonArrowItem *mine = [CMJCommonArrowItem itemWithTitle:@"@我的" icon:nil];
    CMJCommonArrowItem *comment = [CMJCommonArrowItem itemWithTitle:@"评论" icon:nil];
    CMJCommonArrowItem *like = [CMJCommonArrowItem itemWithTitle:@"赞" icon:nil];
    CMJCommonArrowItem *news = [CMJCommonArrowItem itemWithTitle:@"新浪新闻" icon:nil];
    CMJCommonArrowItem *notConcern = [CMJCommonArrowItem itemWithTitle:@"未关注人消息" icon:nil];
    CMJCommonArrowItem *subscribe = [CMJCommonArrowItem itemWithTitle:@"订阅消息" icon:nil];
    CMJCommonArrowItem *radar = [CMJCommonArrowItem itemWithTitle:@"微博雷达" icon:nil];
    CMJCommonArrowItem *secretary = [CMJCommonArrowItem itemWithTitle:@"微博小秘书" icon:nil];
    
    group.items = @[mine,comment,like,news,notConcern,subscribe,radar,secretary];
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *sectionview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 65)];
    sectionview.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    SearchBar *searchB = [[SearchBar alloc] init];
    searchB.frame = CGRectMake(10, 30, self.view.frame.size.width-20, 32);
    [searchB addTarget:self action:@selector(searchBarBeginInput:) forControlEvents:UIControlEventEditingDidBegin];
    searchB.font = [UIFont systemFontOfSize:14];
    searchB.placeholder = @"搜索联系人和群";
    [sectionview addSubview:searchB];
    
    return sectionview;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 65;
}

/** searchbar开始编辑时调用 */
-(void)searchBarBeginInput:(id)sender
{
    UINavigationController *navCtrl = [[UINavigationController alloc] initWithRootViewController:[[FindPeopleController alloc] init]];
    [self presentViewController:navCtrl animated:YES completion:nil];
}

@end
